from socket import*
import sys
class View2:
    def __init__(self,sock):
        self.sock=sock
    def main(self):
        pass
    def check(self):
        pass
    def histry(self):
        pass
    def exit(self):
        pass
class View1:
    def __init__(self,sock):
        self.sock=sock
        self.veiw2= View2(self.sock)
    def choice(self):
        print("""
        +-------在线查单词-------+
        1.登录     2.注册   3.退出
        +-----------------------+""")
        while True:
            choose=input("输入选择序号:")
            if choose=="1":
                self.login()
            if choose=="2":
                self.sign()
            if choose=="3":
                self.exit()
            else:
                print("输入错误!")
    def login(self):
        up=self.upinput()
        login_data=("LOGIN!9p@Yf0"+up).encode()
        self.sock.send(login_data)
        data=self.sock.resv(1024)
        if 200:
            self.veiw2.main()

    def sign(self):
        up=self.upinput()

    def exit(self):
        self.sock.send(b"EXIT!9p@Yf0")
        self.sock.close()
        sys.exit("程序结束!")
    def upinput(self):
        user=input("请输入账户:")
        passwd=input("请输入密码:")
        return user+"!9p@Yf0"+passwd

class Run:
    def __init__(self):
        self.HOST="127.0.0.1"
        self.PORT=8888
        self.sock=self.get_connet()

    def get_connet(self):
        sock=socket()
        sock.connect((self.HOST,self.PORT))
        return sock

    def main(self):
        self.view=View1(self.sock)
        self.view.choice()

if __name__ == '__main__':
    run=Run()
    run.main()